<template>>
    <!-- 总容器 -->
    <div class="wrapper">
        <header>
            <i class="fa fa-angle-left" onclick="history.go(-1)"></i>
            <p>确认您的订单</p>
            <div></div>
        </header>
        <div class="top-ban"></div>

        <section>
            <div class="title">
                <p>体检人信息</p>
            </div>
            <table>
                <tr>
                    <td>姓名:</td>
                    <td>{{ name }}</td>
                </tr>
                <tr>
                    <td>证件号码:</td>
                    <td>{{ identitycard }}</td>
                </tr>
                <tr>
                    <td>出生日期:</td>
                    <td>{{ birthday }}</td>
                </tr>
                <tr>
                    <td>手机号码:</td>
                    <td>{{ phone }}</td>
                </tr>
            </table>
            <div class="title">
                <p>体检日期</p>
            </div>
            <table>
                <tr>
                    <td>{{ date }}</td>
                </tr>
            </table>
            <div class="title">
                <p>体检机构</p>
            </div>
            <table>
                <tr>
                    <td colspan="2">{{ hpname }}</td>
                </tr>
                <tr>
                    <td>营业时间:</td>
                    <td>{{ businesshours }}</td>
                </tr>
                <tr>
                    <td>采血截止:</td>
                    <td>{{ deadline }}</td>
                </tr>
                <tr>
                    <td>机构电话:</td>
                    <td>{{ telephone }}</td>
                </tr>
                <tr>
                    <td>机构地址:</td>
                    <td>{{ address }}</td>
                </tr>
            </table>
            <div class="title">
                <p>套餐类型</p>
            </div>
            <table>
                <tr>
                    <td>{{ smname }}</td>
                </tr>
            </table>
        </section>
        
        <div class="bottom-btn">
            <div class="first">实付款: <span>￥{{ price }}</span></div>
            <div class="last" @click="onSubmit">确认支付</div>
        </div>

        <div class="bottom-ban"></div>
        <footer>
            <ul>
                <li @click="()=>{router.push('/hospital')}">
                    <i class="fa fa-home"></i>
                    <p>云医院</p>
                </li>
                <li @click="()=>{router.push('/setmeal')}">
                    <i class="fa fa-opencart"></i>
                    <p>商城</p>
                </li>
                <li @click="()=>{router.push('/index')}">
                    <i class="fa fa-compass"></i>
                    <p>发现</p>
                </li>
                <li @click="()=>{router.push('/personal')}">
                    <i class="fa fa-user"></i>
                    <p>我</p>
                </li>
            </ul>
        </footer>
    </div>
    
</template>

<script setup>
    import router from '../router'
    import { payApi } from '@/api/User';
    import { addOrderApi } from '@/api/Orders'; 
// import { pa } from 'element-plus/es/locale';

    let user = JSON.parse(sessionStorage.getItem('userInfo'));
    let order = JSON.parse(sessionStorage.getItem('orderdetail'));
    const name = user.realname;
    const identitycard = user.identitycard;
    const phone = user.phone;
    const birthday= user.birthday;
    const telephone = order.telephone;
    const address = order.address;
    const date = order.orderdate;
    const deadline = order.deadline;
    const hpname = order.hpname;
    const smname = order.smname;
    const businesshours = order.businesshours;
    const price = order.price;

    const onSubmit = async () => {
        const payResp = await payApi(JSON.parse(sessionStorage.getItem('userInfo')).userid,price);
        const addorderResp = await addOrderApi(JSON.parse(sessionStorage.getItem('userInfo')).userid,
        JSON.parse(sessionStorage.getItem('orderdetail')).hpid,
        JSON.parse(sessionStorage.getItem('orderdetail')).smid,date);
        if(payResp.code == 200){
            if(addorderResp.code == 200){
                alert(payResp.message);
                alert("预约成功");
                router.push('/appointmentsuccess');
            }else{
                alert("预约失败");
            }
        }else if(payResp.code == 500){
            alert(payResp.message);
        }else{
            alert("支付失败");
            alert("预约失败");
        }
    }
</script>

<style src="../assets/css/confirmorder.css" scoped>
</style>